package com.itheima.controller;

import com.itheima.common.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetMealService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
@Slf4j
@Api(tags = "套餐管理")
@RequiredArgsConstructor
public class SetMealController {
    private final SetMealService setMealService;
    @PostMapping("/getSetmeal")
    public Result getSetmealMessage(){
        Result result = new Result();
        try {
            List<Setmeal> setmeal = setMealService.getSetmeal();
            result.setData(setmeal);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        result.setFlag(true);
        result.setMessage("查询成功");
        return result;
    }

    @PostMapping("/findById")
    public Result findByIdSetMeal(Integer id){
        Result result = new Result();
        try {
            Setmeal setmeal = setMealService.findByIdSetMeal(id);
            result.setData(setmeal);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        result.setFlag(true);
        result.setMessage("查询成功");
        return result;
    }
}
